#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;
class Solution {
public:
    int bitsum(int n)
    {
        int sum = 0;
        while (n)
        {
            int t = n % 10;
            sum += t * t;
            n /= 10;
        }
        return sum;
    }
    bool isHappy(int n) {
        int slow = n, fast = bitsum(n);
        while (slow != fast)
        {
            slow = bitsum(slow);
            fast = bitsum(bitsum(fast));
        }
        return slow == 1;
    }
};
int main()
{
    cout << Solution().isHappy(2) << endl;
	return 0;
}
/*
题目链接:https://leetcode.cn/problems/happy-number/description/
*/
